package com.myway.common.ibe.domain.order;

import java.util.HashMap;

public enum Gender {
	MALE("M"), FEMALE("F");
	
	/**
	 * Alias name. This is the name which will be stored in database.
	 */
	private final String alias;

	/**
	 * A hash map which keep all the gender enum with alias name as key.
	 */
	private static HashMap<String, Gender> map;

	/**
	 * Construct the hash map at load time
	 */
	static {
		map = new HashMap<String, Gender>();
		for (Gender type : Gender.values()) {
			map.put(type.alias, type);
		}
	}

	Gender(String alias) {
		this.alias = alias;
	}

	@Override
	public String toString() {
		return this.alias;

	}

	/**
	 * Return a <code>Gender</code> object holding the value of specified alias name
	 * 
	 * @param alias
	 *            the alias name of the gender
	 * 
	 * @return a <code>Gender</code> object holding the value represented by the alias name
	 *         argument
	 */
	public static Gender valueOfAlias(String alias) {
		Gender type = map.get(alias);

		if (type == null) {
			throw new IllegalArgumentException("Unknown gender alias [" + alias + "]");
		}

		return type;
	}
}
